package band.wukong.practice.webservice.kh.sample05.nongen;

import band.wukong.practice.webservice.kh.sample05.Artist;
import band.wukong.practice.webservice.kh.sample05.JukeboxException_Exception;
import band.wukong.practice.webservice.kh.sample05.JukeboxService;
import band.wukong.practice.webservice.kh.sample05.JukeboxServiceImplService;

import javax.xml.namespace.QName;
import javax.xml.ws.soap.SOAPFaultException;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * wsimport -d d:/ -encoding utf-8 -keep http://localhost:9000/wkp/webservice/kh/sample05?wsdl
 * 1. 给client工程的ServiceImpl增加 @HandlerChain(file = "sample05/handler-chain.xml")
 * 2. Artist加上toString方法
 *
 * @author wukong(wukonggg@139.com)
 */
public class Test {

    public static void main(String[] args) {
//        JukeboxServiceImplService instance = getServiceInstanceProxy();
        JukeboxServiceImplService instance = getServiceInstance();
        JukeboxService service = instance.getJukeboxServiceImplPort();

        Artist none = new Artist();
        try {
            service.removeArtist(none);
        } catch (JukeboxException_Exception e) {
            System.out.println("[Client] [MainApp] JukeboxException_Exception. " + e.getMessage());
        } catch (SOAPFaultException e) {
            System.out.println("[Client] [MainApp] SOAPFaultException. " + e.getMessage());
        }
    }

    private static JukeboxServiceImplService getServiceInstance() {
        return new JukeboxServiceImplService();
    }

    private static JukeboxServiceImplService getServiceInstanceProxy() {
        URL url = null;
        try {
            url = new URL(JukeboxConst.SERVICE_WSDL_DEBUG);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        QName qName = new QName(JukeboxConst.SERVICE_NS, "JukeboxServiceImplService");
        return new JukeboxServiceImplService(url, qName);
    }

}
